﻿using Sidvall.Serialization;

namespace Sidvall.Net.Mail
{
    public class MailMessage
    {
        #region Public Members

        public const string EmailAddressSeparator = ";";

        public string ConnectionString { get; set; }
        public string Subject { get; set; }
        public string Body { get; set; }
        public bool IsBodyHtml { get; set; }
        public string FromAddress { get; set; }
        public string SenderAddress { get; set; }
        public string ReplyToAddresses { get; set; }
        public string RecipientAddresses { get; set; }
        public string CCRecipientAddresses { get; set; }
        public string BccRecipientAddresses { get; set; }
        public AttachmentCollection Attachments { get; private set; }

        #region GetCCRecipientAddressArray

        public string[] GetCCRecipientAddressArray()
        {
            if (!string.IsNullOrWhiteSpace(this.CCRecipientAddresses))
                return this.CCRecipientAddresses.Split(EmailAddressSeparator, System.StringSplitOptions.RemoveEmptyEntries);
            return null;
        }

        #endregion
        #region GetBccRecipientAddressArray

        public string[] GetBccRecipientAddressArray()
        {
            if (!string.IsNullOrWhiteSpace(this.BccRecipientAddresses))
                return this.BccRecipientAddresses.Split(EmailAddressSeparator, System.StringSplitOptions.RemoveEmptyEntries);
            return null;
        }

        #endregion
        #region GetRecipientAddressArray

        public string[] GetRecipientAddressArray()
        {
            if (!string.IsNullOrWhiteSpace(this.RecipientAddresses))
                return this.RecipientAddresses.Split(EmailAddressSeparator, System.StringSplitOptions.RemoveEmptyEntries);
            return null;
        }

        #endregion
        #region GetReplyToAddressArray

        public string[] GetReplyToAddressArray()
        {
            if (!string.IsNullOrWhiteSpace(this.ReplyToAddresses))
                return this.ReplyToAddresses.Split(EmailAddressSeparator, System.StringSplitOptions.RemoveEmptyEntries);
            return null;
        }

        #endregion

        #endregion
        #region Constructors

        public MailMessage()
        {
            this.Attachments = new AttachmentCollection();
        }

        #endregion
    }
}
